package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanBoXinXiSavePO;
import com.ct.application.shipping.model.po.ChuanBoXinXiSearchPO;
import com.ct.application.shipping.model.vo.ChuanBoXinXiVO;
import com.ct.application.shipping.service.ChuanBoXinXiService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 船舶信息配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船舶信息",path="/api/v1/chuanboxinxi",code = "Y1000",sorted = 7)
public class ChuanBoXinXiController extends BaseController {

    @Resource
    private ChuanBoXinXiService chuanBoXinXiService;


    /**
     * 查询船舶信息列表
     * @param chuanBoXinXiSearchPO
     * @return
     */
    @PostMapping("/chuanboxinxi/list")
    @PermissionApi(title = "查询船舶信息列表",path="/api/v1/chuanboxinxi/list",code = "J1001",sorted = 1)
    public Page<ChuanBoXinXiVO> findChuanBoXinXis(@Validated @RequestBody ChuanBoXinXiSearchPO chuanBoXinXiSearchPO) {
        return chuanBoXinXiService.findChuanBoXinXi(chuanBoXinXiSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanboxinxi/saveupdate")
    @ApiLog("船舶信息保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船舶信息保存和更新",path="/api/v1/chuanboxinxi/saveupdate",code = "J1003",sorted = 2)
    public Boolean saveUpdateChuanBoXinXi(@Validated @RequestBody ChuanBoXinXiSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanBoXinXiService.updateChuanBoXinXi(savePO);
        }else {
            return chuanBoXinXiService.saveChuanBoXinXi(savePO);
        }
    }

    /**
     * 根据id查询船舶信息
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanboxinxi/get/{id}")
    @PermissionApi(title = "根据id查询船舶信息",path="/api/v1/chuanboxinxi/get/{id}",code = "J1004",sorted = 3)
    public ChuanBoXinXiVO getChuanBoXinXiById(@PathVariable("id") Long id) {
        return chuanBoXinXiService.getChuanBoXinXi(id);
    }


    /**
     * 根据id删除船舶信息
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanboxinxi/del/{id}")
    @ApiLog("根据id删除船舶信息")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船舶信息",path="/api/v1/chuanboxinxi/del/{id}",code = "J1005",sorted = 4)
    public Boolean delChuanBoXinXiById(@PathVariable("id") Long id) {
        return chuanBoXinXiService.del(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanboxinxi/update/status")
    @ApiLog("船舶信息修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船舶信息修改状态",path="/api/v1/chuanboxinxi/update/status",code = "J1006",sorted = 5)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanBoXinXiService.updateStatus(statusRequest);
    }


    /**
     * 查询船舶信息列表
     * @return
     */
    @PostMapping("/chuanboxinxi/listbiao")
    @PermissionApi(title = "查询船舶信息列表2",path="/api/v1/chuanboxinxi/listbiao",code = "J1007",sorted = 7)
    public List<ChuanBoXinXiVO> findChuanBoXinXisList() {
        return chuanBoXinXiService.findChuanBoXinXisList();
    }
}
